﻿var jQ = jQuery(document);

var systemCommon =
{
    init: function() { // Após inicialização do script.
        systemCommon.domManipulation.init();
    },
    ajaxStop: function() { // Após o termino de cada requisição ajax.
        systemCommon.domManipulation.listDeslogadoLink();
    },
    windowOnload: function() { // Após a inicialização do documento.
        systemCommon.loadPlugins.init();
        systemCommon.methods.init();
    },
    loadPlugins: { // Definindo os plugins.
        init: function() {
            systemCommon.loadPlugins.thumbnailSlide();
        },
        thumbnailSlide: function() {
            $('#product #show .thumbs').jQRoll({ 
                containerLimit : 4,
                moveSize : 66 
            });
        }
    },
    domManipulation: { // Manipulações do Dom.
        init: function() {
            //systemCommon.domManipulation.breadcrumbManip();
            systemCommon.domManipulation.leftsizeManip();
            
        },
        showShadow: function() {
            $('.shadow').fadeIn();
        },
        hideShadow: function() {
            $('.shadow').fadeOut();
        },
        showMeasures: function(){
            var box = $('.measuresbox');
            var hDiference = $(box).width() / 2;
            var vDiference = ( $(window).height() > $(box).height() ? ( $(window).height() - $(box).height() ) / 2 : 0 );
            
            $(box).show().css({ 'top' : vDiference + 'px' , 'margin-left' : "-" + hDiference + 'px'  });
        },
        animateMeasures: function(){
            var box = $('.measuresbox');
            var hDiference = $(box).width() / 2;
            var vDiference = ( $(window).height() > $(box).height() ? ( $(window).height() - $(box).height() ) / 2 : 0 );
            
            $(box).show().css({ 'margin-left' : "-" + hDiference + 'px'  }).animate({ 'top' : vDiference + 'px' });
        },
        hideMeasures: function(){
            $('.measuresbox').hide();
        },
        leftsizeManip: function() {
            var content = $('#product');
            var leftside = $('#left-side');
            if ( $(content).height() > $(leftside).height() ){
            
                $(leftside).css({   
                    'position' : 'absolute'
                });
            
            }
        },
        listDeslogadoLink: function() {
            if ( $('.wishlist .giftlist .giftlistcreate-nouser').length > 0 ){
                $('.wishlist .giftlist .giftlistcreate-nouser').attr({ 'href' : '/Site/Login.aspx?ReturnUrl=%2flista%2fcriar' });
            }
        }
    },
    methods: { // Métodos.
        init: function() {
            systemCommon.methods.changeMeasureTabs();
            systemCommon.methods.measureBoxEvents();
        },
        changeMeasureTabs: function() {
            $('.measuresbox .measureheader ul li a').click(function(){
                var index = $(this).index('.measuresbox .measureheader ul li a');
                var tabs = $('.measuresbox .measureheader ul li a');
                var boxes = $('.measuresbox .boxes .box');
                
                $(tabs).removeClass();
                $(boxes).hide().eq(index).show();
                $(this).addClass('active');
                systemCommon.domManipulation.animateMeasures();
            });
        },
        measureBoxEvents: function() {
            $('#insertmneasures').click(function(){
                systemCommon.domManipulation.showShadow();
                systemCommon.domManipulation.showMeasures();
            });
            $('.shadow, .measureheader h2 .close, .measuresbox .actions ul li .cancelar').click(function(){
                systemCommon.domManipulation.hideShadow();
                systemCommon.domManipulation.hideMeasures();
            });
        }
    }
};


jQuery(function() { systemCommon.init(); jQ.ajaxStop(function() { systemCommon.ajaxStop(); }); });
jQuery(document).ready(function() 
{ 
	$('.similares-cores.n1colunas:eq(1)').remove();
	systemCommon.windowOnload();
	$('div.clearfix.moresugests a').attr('href', $('.bread-crumb ul .last a').attr('href'));
	//colors
	jQuery(document).ajaxComplete(function(){
		var back = "";
		$('.similar.product .similares-cores > a').each(function(){
			back = $(this).find('ul li').attr('class');
			if(back == undefined){
				back='';
			}
			if (back.length>7){
				$(this).css('background-image', 'url('+back+')');
			}else{
				$(this).css('background-color', '#'+back+'');
			}
		});
	});
});
